import java.util.ArrayList;
import java.util.HashMap;


public class TablaSimbolos {
	 
	private ArrayList<HashMap<String,RegistroProp>> tablanivel;
	private int nivel;


    public TablaSimbolos(){
    	HashMap<String,RegistroProp> tabla;
        tabla = new HashMap<String,RegistroProp>();
        tabla.put("integer",new RegistroProp(new Props(tipot.integer,"integer"), "tipo", 1));
        tabla.put("real",new RegistroProp(new Props(tipot.real,"real"), "tipo", 1));
        tablanivel=new ArrayList<HashMap<String,RegistroProp>>();
        tablanivel.add(tabla);
        nivel=0;
    }
    
    public void aumentaNivel(){
    	nivel++;
    	HashMap<String,RegistroProp> tabla;
        tabla = new HashMap<String,RegistroProp>();
        tablanivel.add(nivel,tabla);
    }
    
    public void disminuyeNivel(){
        tablanivel.remove(nivel);
        nivel--;
    }

    public void addID(String id, RegistroProp registro){
    	if (!existeID(id,nivel)){
    		tablanivel.get(nivel).put(id, registro);
    	}else System.out.println("Error. Ya existe el iden");//error si iden repetido
    }

    public boolean existeID(String id){
    	for (int i=nivel;i>=0;i--)
    	  if (tablanivel.get(i).containsKey(id)) return true;
    	  return false;
    }

    public RegistroProp props(String id){
    	RegistroProp tipo=null;
    	for (int i=nivel;i>=0;i--)
    		if(existeID(id,i))
    			return tipo=tablanivel.get(i).get(id);
        return tipo;
    }

	public boolean existeID(String id, int nivel2) {
		if (tablanivel.get(nivel2).containsKey(id)) return true;
	    return false;
	}

	public void addID(String id, RegistroProp registroProp, int i) {
		if (!existeID(id,nivel)){
    		tablanivel.get(i).put(id, registroProp);
    	}else System.out.println("Error. Ya existe el iden");//error si iden repetido
		
	}

	public int nivel(String lex) {
		for (int i=nivel;i>=0;i--)
    		if(existeID(lex,i))
    			return i;
        return -1;
	}
}
